﻿//  -------------------- iSharePoint -------------------- //
// 
//  Company:	IT Complex, LLC
//  Project:	Smart.Common
//  File name:	Const.cs
//  Developer:	Solomatov Igor
//  Created:	15.04.2012
// 
//  -------------------- iSharePoint -------------------- //

using System;
using System.ComponentModel;
using System.Text.RegularExpressions;
using System.Threading;

namespace Smart.Common
{
	[Localizable(false)]
	public static class Common
	{
		public static readonly SPResources Resources = new SPResources("Smart.Common");

		public static string GetLocalizedString(string key)
		{
			return Resources.GetLocalizedString(key);
		}

		public static string Localized(this string key)
		{
			return GetLocalizedString(key);
		}

		public static bool IsLocalizationKey(this string key)
		{
			return key != null && key.StartsWith("$Resources", StringComparison.OrdinalIgnoreCase);
		}
	}

	/// <summary>
	/// All project constants
	/// </summary>
	public static class Const
	{
		public const string EmailPattern =
			@"^(([\w-]+\.)+[\w-]+|([a-zA-Z]{1}|[\w-]{2,}))@((([0-1]?[0-9]{1,2}|25[0-5]|2[0-4][0-9])\.([0-1]?[0-9]{1,2}|25[0-5]|2[0-4][0-9])\.([0-1]?[0-9]{1,2}|25[0-5]|2[0-4][0-9])\.([0-1]?[0-9]{1,2}|25[0-5]|2[0-4][0-9])){1}|([a-zA-Z]+[\w-]+\.)+[a-zA-Z]{2,4})$";

		public static readonly Regex RegexEmail = new Regex(EmailPattern, RegexOptions.Compiled);

		static Const()
		{
		}

		/// <summary>
		/// Constants for configuration
		/// </summary>
		public static class Configuration
		{
			/// <summary>
			/// Main settings list url
			/// </summary>
			public const string MainListUrl = "Lists/Settings";
			/// <summary>
			/// User settings list url
			/// </summary>
			public const string UserListUrl = "Lists/UserSettings";

			//public const string ConfigurationCacheKey = "Conf";
			//public const string ConfigurationExceptionMessage = "Configuration element not found";

			public const string RootSubjectKeyword = "Root";

			/// <summary>
			/// Configuration content type id
			/// </summary>
			public const string ContentTypeId = "0x0100D984D6CFE8D2424AA84D26F722699710";

			/// <summary>
			/// Maximum value length
			/// </summary>
			public const int MaxValueLength = 16384;

			public static readonly Guid SubjectField = new Guid("{91361C51-8D28-42EB-8940-8FFB0F425002}");
			public static readonly Guid ValueField = new Guid("{4D173D8E-C667-45B4-9009-073062F179DD}");
		}

		/// <summary>
		/// Context configuration keys
		/// </summary>
		public static class Context
		{
			public const string AddonConfigListKey = "Base.AddonList";

			public const string RegisteredAddonConfigListKey = "Base.RegisteredAddonList";

			public const string ScopeConfigKeyTempl = "Scope.{0}";
		}

		/// <summary>
		/// Metadata settings
		/// </summary>
		public static class Metadata
		{
			/// <summary>
			/// Web Scope prefix
			/// </summary>
			public const string WebScopePrefix = "SPW:";
		}

		/// <summary>
		/// Cache information
		/// </summary>
		public class Cache
		{
			/// <summary>
			/// Request cache key
			/// </summary>
			public const string RequestKey = "rc";

			/// <summary>
			/// Configuration сache key 
			/// </summary>
			public const string ConfigurationKey = "cvc";

			/// <summary>
			/// List service cache key
			/// </summary>
			public const string ListServiceKey = "lsc";

			/// <summary>
			/// Metadata cache key
			/// </summary>
			public const string MetadataKey = "mdc";

			/// <summary>
			/// Disposable map cache key
			/// </summary>
			public const string DisposableMapKey = "dmk";

			/// <summary>
			/// Disposable list cache key
			/// </summary>
			public const string DisposableListKey = "dlk";

			/// <summary>
			/// Site groups cache
			/// </summary>
			public const string GroupsCache = "sgc";

			/// <summary>
			/// Router requests key (in RouterService)
			/// </summary>
			public const string RouterRequests = "rsrc";

			/// <summary>
			/// Router templates tree key (in XmlRouterSource)
			/// </summary>
			public const string RouterTemplatesTree = "rstc";
		}

		/// <summary>
		/// Timer Jobs Settings
		/// </summary>
		public static class TimerJobs
		{
			/// <summary>
			/// Timer job event names
			/// </summary>
			public static class Events
			{
				/// <summary>
				/// Job executing, args: SPJob, SPWeb
				/// </summary>
				public const string JobExecuting = "JobExecuting";

				/// <summary>
				/// Job executing, args: SPJob, SPWeb
				/// </summary>
				public const string JobExecutingTempl = "JobExecuting-";
			}

			/// <summary>
			/// Notification sender job
			/// </summary>
			public static class Notification
			{
				public const int OneTimeMessagesCount = 20;
				public const int MaxSendingAttempts = 5;

				public const string JobName = "NotificationSenderJob";
			}

			/// <summary>
			/// Cleanup temp document library job settings
			/// </summary>
			public static class Cleanup
			{
				public const string JobName = "CleanupJob";
			}
		}

		/// <summary>
		/// Templates
		/// </summary>
		public static class Templates
		{
			/// <summary>
			/// Html templates
			/// </summary>
			public const string Html = "html";
		}

		public static class Template
		{
			/// <summary>
			/// Symbol surrounds the tag
			/// </summary>
			public const string TagSymbol = @"##";

			/// <summary>
			/// Symbol surrounds the tag
			/// </summary>
			public const string TagSymbol2 = @"--";

			/// <summary>
			/// Surrounding tag
			/// </summary>
			public const string TagTempl = "##{0}##";
		}

		/// <summary>
		/// Entity type names
		/// </summary>
		public static class EntityNames
		{
			/// <summary>
			/// Generic entity
			/// </summary>
			public const string Entity = "entity";

			/// <summary>
			/// NotificationTemplate entity
			/// </summary>
			public const string NotificationTemplate = "notifications.template";

			/// <summary>
			/// NotificationItem entity
			/// </summary>
			public const string NotificationItem = "notifications.item";
		}

		/// <summary>
		/// Entity facade type names
		/// </summary>
		public static class FacadeNames
		{
			/// <summary>
			/// MessageTemplates facade
			/// </summary>
			public const string MessageTemplates = "notifications.templates";

			/// <summary>
			/// MessageQueue facade
			/// </summary>
			public const string MessageQueue = "notifications.queue";
		}

		/// <summary>
		/// Scope type names
		/// </summary>
		public static class ScopeNames
		{
			/// <summary>
			/// Notifications scope
			/// </summary>
			public const string Notifications = "Notifications";
		}

		/// <summary>
		/// List fields identifications
		/// </summary>
		public static class Guids
		{
			public static class NotificationItem
			{
				public const string SendAt = "{38A6609A-2406-45D3-876B-58302512EB8A}";
			}
		}

		/// <summary>
		/// Security class constants
		/// </summary>
		public static class Security
		{
			/// <summary>
			/// Security matrix configuration key template
			/// </summary>
			public const string SecurityConfKeyTempl = "SecurityMatrix.{0}";
		}

		/// <summary>
		/// Forms constants
		/// </summary>
		public static class Forms
		{
			/// <summary>
			/// Default rules service name
			/// </summary>
			public const string DefaultRulesServiceName = "forms.rules";

			/// <summary>
			/// Form with qsvalues javascript enabled
			/// </summary>
			public const string QSListFormTemplate = "QSListForm";

			/// <summary>
			/// Xml forms definition
			/// </summary>
			public static class XmlForms
			{
			}

			/// <summary>
			/// SharePoint forms constants
			/// </summary>
			public static class WebForms
			{
				/// <summary>
				/// SharePoint list form service name
				/// </summary>
				public const string ListFormsServiceName = @"ListForms";

				/// <summary>
				/// SharePoint list form template name
				/// </summary>
				public const string ListFormTemplate = @"SPListForm";

				/// <summary>
				/// SharePoint list form template name
				/// </summary>
				public const string KDocSetFormTemplate = @"SPDocSetDisplayForm";

				/// <summary>
				/// Default SharePoint forms service configuration key
				/// </summary>
				public const string DefaultFormsServiceConfigKey = @"Forms.ListForms.Default";

				/// <summary>
				/// Register directive config key
				/// </summary>
				public const string FormsRegisterConfigKey = @"Forms.ListForms.Register";

				/// <summary>
				/// Register directive default value
				/// </summary>
				public const string FormsRegisterDefault =
					@"<%@ Register TagPrefix=""SharePoint"" Assembly=""Microsoft.SharePoint, Version=14.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c"" Namespace=""Microsoft.SharePoint.WebControls"" %>";

				/// <summary>
				/// Forms table class
				/// </summary>
				public const string TableClass = @""; //ms-formtable

				/// <summary>
				/// Forms table row class
				/// </summary>
				public const string TableRowClass = @"";

				/// <summary>
				/// Forms table row class
				/// </summary>
				public const string TableCellClass = @"ms-vb";

				/// <summary>
				/// Field group heading
				/// </summary>
				public const string FieldGroupHead = @"<table class=""ms-formtable"" style=""margin-top: 8px;"" border=""0"" cellpadding=""0"" cellspacing=""0"" width=""100%"">";

				/// <summary>
				/// Field group item heading
				/// </summary>
				public const string FieldGroupItemHead = @"<tr>";

				/// <summary>
				/// Field group item tail
				/// </summary>
				public const string FieldGroupItemTail = @"</tr>";

				/// <summary>
				/// Field group tail
				/// </summary>
				public const string FieldGroupTail = @"</table>";
			}
		}

		/// <summary>
		/// Router
		/// </summary>
		public static class Router
		{
			public static class LibTemp
			{
				/// <summary>
				/// Router key of document library which stores temporary files 
				/// </summary>
				public const string RouterKey = "libs.temp";

				/// <summary>
				/// Router key of document library which stores temporary files 
				/// </summary>
				public const string RouterType = "SPList";

				/// <summary>
				/// Router key of document library which stores temporary files 
				/// </summary>
				public const string RouterUri = "/Temp";
			}

			/// <summary>
			/// Web router
			/// </summary>
			public static class Web
			{
				/// <summary>
				/// Configuration setting name
				/// </summary>
				public const string ConfigSettingName = "Router.Settings";

				/// <summary>
				/// WebRouterService type name
				/// </summary>
				public const string ServiceName = @"WebRouterService";

				/// <summary>
				/// Tags using in template uri
				/// </summary>
				public static class Tags
				{
					/// <summary>
					/// Name of the current web
					/// </summary>
					public const string WebName = @"web:name";

					/// <summary>
					/// Url of the current web
					/// </summary>
					public const string WebUrl = @"web:url";

					/// <summary>
					/// Field value of the current entity
					/// </summary>
					public const string Field = @"field:";
				}
			}
		}

		/// <summary>
		/// EventManager events
		/// </summary>
		public static class EventNames
		{
			///// <summary>
			///// PrivateOffice events
			///// </summary>
			//public static class PrivateOffice
			//{
			//    /// <summary>
			//    /// Load private office definition (args: PrivateOfficeFactory, PrivateOfficeFactory.DefinitionInfo)
			//    /// </summary>
			//    public const string LoadDefinition = "PrivateOffice.LoadDefinition";
			//}

			/// <summary>
			/// Forms events
			/// </summary>
			public static class Forms
			{
				/// <summary>
				/// Parse xml event name template (args: XmlFormsBuilder.ParseEventInfo)
				/// </summary>
				public const string ParseXml = "Forms.XmlForms.Parse.{0}";

				/// <summary>
				/// Add control event name template (args: WebFormsFormatter.AddEventInfo)
				/// </summary>
				public const string AddWebCtrl = "Forms.WebForms.AddCtrl.{0}";

				/// <summary>
				/// BuildForm: Context inited (args: FormsContext, FormsService)
				/// </summary>
				public const string FormsCtxInited = "Forms.CtxInited.{0}";

				/// <summary>
				/// BuildForm: Forms definition loaded (args: FormsContext, FormsService)
				/// </summary>
				public const string FormsDefinitionLoaded = "Forms.DefinitionLoaded.{0}";

				/// <summary>
				/// BuildForm: Forms definition parsed (args: FormsContext, FormsService)
				/// </summary>
				public const string FormsDefinitionParsed = "Forms.DefinitionParsed.{0}";

				/// <summary>
				/// BuildForm: Context values loaded (args: FormsContext, FormsService)
				/// </summary>
				public const string FormsCtxValuesLoaded = "Forms.CtxValuesLoaded.{0}";

				/// <summary>
				/// BuildForm: Form choosed (args: FormsContext, FormsService)
				/// </summary>
				public const string FormsFormChoosed = "Forms.FormChoosed.{0}";

				/// <summary>
				/// BuildForm: Form security checked and pass (args: FormsContext, FormsService)
				/// </summary>
				public const string FormsSecurityChecked = "Forms.SecurityChecked.{0}";

				/// <summary>
				/// BuildForm: Process form after form values filled (args: FormsContext, FormsService)
				/// </summary>
				public const string FormsProcessAfterFill = "Forms.AfterFill.{0}";

				/// <summary>
				/// BuildForm: Process form after form values filled (args: FormsContext, FormsService)
				/// </summary>
				public const string FormsProcessAfterLoad = "Forms.AfterLoad.{0}";

				/// <summary>
				/// BuildForm: Process form after form rules processed (args: FormsContext, FormsService)
				/// </summary>
				public const string FormsProcessAfterRules = "Forms.AfterRules.{0}";
			}

			public static class System
			{
				/// <summary>
				/// System: define controls on system page (args: Page, ControlCollection)
				/// </summary>
				public const string DefineControls = "System.DefineControls";

				/// <summary>
				/// System: update controls on system page (args: Page, ControlCollection, bool updateValues)
				/// </summary>
				public const string UpdateControls = "System.UpdateControls";

				/// <summary>
				/// System: update controls on system page (args: Page, ControlCollection)
				/// </summary>
				public const string CheckErrors = "System.CheckErrors";

				/// <summary>
				/// System: update controls on system page (args: Page, ControlCollection)
				/// </summary>
				public const string CorrectErrors = "System.CorrectErrors";
			}
		}

		public static class Rules
		{
			public const string RulesName = "Rules";
			public const string RuleName = "Rule";
			public const string ActionName = "Action";
			public const string ConditionName = "Condition";
		}
	}
}